package com.softer.chengxin.project.dao;

import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.project.dao.provider.ProprietorDaoProvider;
import com.softer.chengxin.project.domin.Proprietor;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2018/10/16
 */
@Mapper
@Repository
public interface ProprietorDao {
    /**
     * 增加业主委员会成员
     *
     * @param proprietor 成员实体
     * @return 结果
     */
    @Insert("INSERT INTO company_proprietor(project_id,name,sex,age,education_level,company,phone,business_address,address,duty,political_status,state,housing_area,remark,gmt_create,gmt_modified)" +
            " VALUES(#{p.projectId},#{p.name},#{p.sex},#{p.age},#{p.educationLevel},#{p.company},#{p.phone},#{p.businessAddress},#{p.address},#{p.duty},#{p.politicalStatus},#{p.state},#{p.housingArea},#{p.remark},now(),now())")
    int add(@Param("p") Proprietor proprietor);

    /**
     * 查询业主委员会人员数量
     *
     * @param proprietor 查询实体
     * @return 数量
     */
    @SelectProvider(type = ProprietorDaoProvider.class, method = "queryNum")
    int queryNum(@Param("proprietor") Proprietor proprietor);

    /**
     * 查询业主委员会人员数量
     *
     * @param page       页面实体
     * @param proprietor 查询实体
     * @return 数量
     */
    @SelectProvider(type = ProprietorDaoProvider.class, method = "queryList")
    List<Proprietor> queryList(@Param("page") Page page, @Param("proprietor") Proprietor proprietor);

    /**
     * 查看业主委员会成员详情
     *
     * @param id 成员ID
     * @return 详情
     */
    @Select("SELECT id,project_id as projectId,`name`,sex,age,education_level as educationLevelCode,(SELECT name FROM dic_info WHERE code = education_level) AS educationLevel,company," +
            "phone,business_address as businessAddress,address, duty AS dutyCode,(SELECT name FROM dic_info WHERE code = duty) AS duty,political_status as politicalStatus," +
            "state,housing_area as housingArea,remark from company_proprietor WHERE id=#{id}")
    Proprietor detail(@Param("id") Integer id);

    /**
     * 删除业主委员会成员
     *
     * @param id 成员ID
     * @return 结果
     */
    @Delete("delete from company_proprietor where id = #{id}")
    int delete(@Param("id") Integer id);

    /**
     * 编辑业主委员会成员
     *
     * @param proprietor 成员实体
     * @return 结果
     */
    @Update("update company_proprietor set gmt_modified=now(),name=#{p.name},sex=#{p.sex},age=#{p.age},education_level=#{p.educationLevel}," +
            "company=#{p.company},phone=#{p.phone},business_address=#{p.businessAddress},address=#{p.address},duty=#{p.duty}" +
            ",political_status=#{p.politicalStatus},state=#{p.state},housing_area=#{p.housingArea},remark=#{p.remark} where id=#{p.id}")
    int edit(@Param("p") Proprietor proprietor);
}
